package com.weight.common.generate.temple;

import java.util.List;
import java.util.Map;

import com.weight.common.generate.base.ResourceFile;


/**
* 
*  
*/
public class AddHtmlResourceFileNew extends ResourceFile {
	private static final String FILE_NAME = ".html";
	
	public AddHtmlResourceFileNew(String filePath,String packageName,String model,List<String> fieldENList,List<String> fieldCNList,String tableCnName) {
		
		super(filePath,new StringBuilder("add").append(getModelClass(model)).append(FILE_NAME).toString());
		
		StringBuilder beanName=getModelClass(model);
		StringBuilder  resourceFile =new StringBuilder();
		
		resourceFile.append("<!DOCTYPE html>\n" + 
				"<html>\n" + 
				"<head>\n" + 
				"  <title>"+tableCnName+"添加</title>\n" + 
				"  <meta charset=\"utf-8\">\n" + 
				"  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n" + 
				"  <link rel=\"stylesheet\" href=\"bootstrap4/css/bootstrap.min.css\">\n" + 
				"  <link rel=\"stylesheet\" href=\"css2/style2.css\"> \n" + 
				"  <script src=\"http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js\"></script>\n" + 
				"  <script src=\"http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js\"></script>\n" + 
				"  <script src=\"js2/my.js\"></script>\n" + 
				"</head>\n" + 
				"\n" + 
				"<script type=\"text/javascript\">\n" + 
				"$(function(){\n" + 
				"	$(\"#formID\").validate({\n" + 
				"        rules: {\n" );
		for(int i=1;i<fieldENList.size();i++) {
		
			if(i == fieldENList.size()-1 ) {
				resourceFile.append( 
						"            \""+fieldENList.get(i)+"\": {\n" + 
						"                required: true\n" + 
						"            }\n");
			}else {
				resourceFile.append( 
						"            \""+fieldENList.get(i)+"\": {\n" + 
						"                required: true\n" + 
						"            },\n");
			}
		}
		
		
		resourceFile.append(  
				"        },\n" + 
				"        messages:{\n" );
for(int i=1;i<fieldENList.size();i++) {
			
			if(i == fieldENList.size()-1 ) {
				resourceFile.append( 
						"            \""+fieldENList.get(i)+"\": {\n" + 
						"                required: \""+fieldCNList.get(i)+"不能为空\"\n" + 
						"            }\n");
			}else {
				resourceFile.append( 
						"            \""+fieldENList.get(i)+"\": {\n" + 
						"                required: \""+fieldCNList.get(i)+"不能为空\"\n" + 
						"            },\n");
			}
		} 
		resourceFile.append(  
				"        },\n" + 
				"        submitHandler:function(form){\n" + 
				"        	$.ajax({\n" + 
				"        		type: \"POST\",//方法类型\n" + 
				"                dataType: \"json\",//预期服务器返回的数据类型\n" + 
				"                url: \"save"+beanName+"\" ,//url\n" + 
				"                data: $('#formID').serialize(),\n" + 
				"                success: function (result) {\n" + 
				"                    console.log(result);//打印服务端返回的数据(调试用)\n" + 
				"                    if (result.code == 200) {\n" + 
				"                        if(confirm(result.msg+'是否继续？？'))\n" + 
				"                        {   \n" + 
				"                        	 window.location.href = \"add"+beanName+"\";\n" + 
				"                        }\n" + 
				"                        else\n" + 
				"                        {  \n" + 
				"                        	 window.location.href = \"queryFor"+beanName+"List\";\n" + 
				"                        }\n" + 
				"                    }\n" + 
				"                    else{                	\n" + 
				"                    	alert(result.msg);\n" + 
				"                    }\n" + 
				"                     \n" + 
				"                },\n" + 
				"                error : function() {\n" + 
				"                    alert(\"异常！\");\n" + 
				"                }\n" + 
				"            });\n" + 
				"        },\n" + 
				"        //自定义错误样式\n" + 
				"        errorClass:\"text-danger\",\n" + 
				"        //未通过验证,进行高亮处理或其他处理；\n" + 
				"        highlight:function(input){\n" + 
				"            $(input).closest(\".form-group\").addClass(\"has-error\");\n" + 
				"        },\n" + 
				"        //通过验证,清除高亮效果或其他处理；\n" + 
				"        unhighlight:function(input){\n" + 
				"            $(input).closest(\".form-group\").removeClass(\"has-error\");\n" + 
				"        }\n" + 
				"	});\n" + 
				"});\n" + 
				"\n" + 
				
				"</script>\n" + 
				"<body>\n" + 
				"<div class=\"header-area\" id=\"headerArea\">\n" + 
				"   <div class=\"container h-100 d-flex align-items-center justify-content-between\">\n" + 
				" \n" + 
				"     <div class=\"logo-wrapper\">\n" + 
				"     <a th:href=\"@{/queryFor"+beanName+"List}\"> 返回 </a>\n" + 
				"	 </div>\n" + 
				"     <!-- Search Form-->\n" + 
				"     <div class=\"top-search-form\">\n" + 
				"      	 "+tableCnName+"添加\n" + 
				"     </div>\n" + 
				"     <div  id=\"suhaNavbarToggler\"><span></span><span></span><span></span></div>\n" + 
				"   </div>\n" + 
				" </div>\n" + 
				"\n" + 
				"<div class=\"container mt60\">\n" + 
				"  <form id=\"formID\"  >\n" + 
				"  	<input type=\"hidden\" name=\""+fieldENList.get(0)+"\" th:value=\"${"+model+"VO?."+fieldENList.get(0)+"}\" /> \n" + 
				"    <div class=\"form-group\">\n" + 
				"       <div class=\"single-payment-method\"> \n" + 
				"       		<img class=\"mb-3\" src=\"img/bg-img/9.jpeg\"   width=\"100%\"alt=\"\">\n" + 
				"       </div>\n" + 
				"    </div>\n" );
		

for(int i=1;i<fieldENList.size();i++) {
			 
			resourceFile.append(  
					"    <div class=\"form-group\"> \n" + 
					"      <label class=\"title fl\"></label>\n" + 
					"      <label for=\""+fieldENList.get(i)+"\" class=\"fl\" >"+fieldCNList.get(i)+":</label>\n" + 
					"      <input type=\"text\" class=\"form-control\" id=\""+fieldENList.get(i)+"\" placeholder=\"请填写"+fieldCNList.get(i)+"\" \n" + 
					"      name=\""+fieldENList.get(i)+"\"\n" + 
					"      th:value=\"${"+model+"VO?."+fieldENList.get(i)+"}\" >\n" + 
					"    </div>\n" );
			
		} 
		
		resourceFile.append(  
				"     <button type=\"submit\" class=\"btn btn-primary btn-block\" >提交</button>\n" + 
				"  </form>\n" + 
				" \n" + 
				"</div>\n" + 
				"\n" + 
				"</body>\n" + 
				"</html>"
				+ "");
		 
		
		
		resourceFile.append("\n");
		
		String resource = resourceFile.toString();
		init(resource);
	}
}
